package com.renge.vodservice.controller;

import com.renge.commonutils.R;
import com.renge.vodservice.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(description="OVD视频管理")
@RestController
@CrossOrigin
@RequestMapping("/eduvod")
public class VodController {
     @Autowired
    private VodService VodService;
    @ApiOperation(value = "上传视频到阿里云返回视频id")
    @PostMapping("/uploadvod")
    public R uploadVod(@ApiParam(name = "file",value = "视频文件",required = true)
                            MultipartFile file){
        String vodId = VodService.uploadVod(file);
        if(StringUtils.isEmpty(vodId)){
            return R.error();
        }
        return R.ok().data("videoId",vodId);
    }
    @ApiOperation(value = "根据视频id删除阿里云上的视频")
    @DeleteMapping("{videoId}")
    public R deleteVideoById(@ApiParam(name = "videoId",value = "视频id",required = true)
                              @PathVariable("videoId")String videoId){
        VodService.deleteVideoById(videoId);
        return R.ok();
    }
    @ApiOperation(value = "根据视频id获得播放凭证")
    @GetMapping("/player/{videoId}")
    public R getPlayAuthById(@ApiParam(name = "videoId",value = "视频id",required = true)
                             @PathVariable("videoId")String videoId){

        String playAuthId = VodService.getPlayAuthById(videoId);
        return R.ok().data("playAuthId",playAuthId);
    }
}
